"use strict";
cc._RF.push(module, 'f18eeFik3VKoYdMHbWrWLJB', 'SellItem');
// scripts/SellItem.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("CarConstant"),
    s = t("Hint"),
    l = t("BroadCastMessage"),
    c = t("Util"),
    d = t("HallConstant"),
    h = t("AssemblyItem"),
    p = cc._decorator,
    u = p.ccclass,
    f = p.property,
    m = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.pfb_assemblyItem = null, e.node_item = null, e.lab_name = null, e.lab_level = null, e.node_hp = null, e.node_elec = null, e.node_damage = null, e.arrNode_star = new Array(5), e.arr_starIcons = new Array(), e.node_check = null, e.assemblyItem = null, e.nCurStar = 0, e._itemData = null, e.nSellGold = 0, e._sellView = null, e;
  }

  return n(e, t), e.prototype.init = function (t) {
    this._sellView = t;
  }, e.prototype.onBtnCheck = function () {
    this._itemData && null != this._itemData.video && this._itemData.video ? s["default"].show("此组件无法出售") : (this.playAudio(d.Audio_ID.btn_click), this.node_check.active ? this.onCancelCheckHandle() : this.onCheckHandle());
  }, e.prototype.onCheck = function (t, e) {
    this._itemData && null != this._itemData.video && this._itemData.video || this.nCurStar == e && (t && !this.node_check.active ? this.onCheckHandle() : !t && this.node_check.active && this.onCancelCheckHandle());
  }, e.prototype.onCheckHandle = function () {
    this.node_check.active = !0, this._sellView.onSetSellGold(!0, this.nSellGold);
  }, e.prototype.onCancelCheckHandle = function () {
    this.node_check.active = !1, this._sellView.onSetSellGold(!1, this.nSellGold);
  }, e.prototype.getSellGold = function () {
    return c.Util.transformSellGold(this._itemData.level);
  }, e.prototype.getSellData = function () {
    return this.node.active && this.node_check.active ? this._itemData : null;
  }, e.prototype.getIsCheck = function () {
    return this.node_check.active;
  }, e.prototype.onActive = function (t) {
    this.node.active = t;
  }, e.prototype.updateItem = function (t, e) {
    this._itemData = e, this.onActive(!0), this.node_check.active = !1, this.nSellGold = c.Util.transformSellGold(e.level), this.setStarQuality(), this.setLabelString(e), this.createItem(e), this.setAttributeString(e), this.showStar(e.star);
  }, e.prototype.setAttributeString = function (t) {
    var e = [cc.v3(-57, 0), cc.v3(18, 0), cc.v3(18, 0)],
        o = 0,
        i = [];
    if (t.hp ? (this.node_hp.active = !0, o++, i.push(this.node_hp), this.node_hp.getChildByName("label").getComponent(cc.Label).string = "" + c.Util.transformHpNum(t.hp, t.level)) : this.node_hp.active = !1, t.damage ? (this.node_damage.active = !0, o++, i.push(this.node_damage), this.node_damage.getChildByName("label").getComponent(cc.Label).string = "" + c.Util.transformDamageNum(t.damage, t.level)) : this.node_damage.active = !1, t.elec ? (this.node_elec.active = !0, o++, i.push(this.node_elec), this.node_elec.getChildByName("label").getComponent(cc.Label).string = "" + t.elec) : this.node_elec.active = !1, 1 == o) i[0].position = cc.v3(-18, 0, 0);else for (var n = 0; n < i.length; n++) {
      i[n].position = e[n];
    }
  }, e.prototype.setStarQuality = function (t) {
    void 0 === t && (t = 0);

    for (var e = 0; e < this.arrNode_star.length; e++) {
      this.arrNode_star[e].getComponent(cc.Sprite).spriteFrame = this.arr_starIcons[t];
    }
  }, e.prototype.setLabelString = function (t) {
    switch (t.type) {
      case r.Basics_Items_Type.body:
        var e = r.GetCarBodyData(t.id);
        t.quality && this.setStarQuality(t.quality), this.lab_name.string = "" + e.name, this.lab_level.string = (t.level || "1") + "级";
        break;

      case r.Basics_Items_Type.wheel:
        var o = r.GetCarWheelData(t.id);
        this.lab_name.string = "" + o.name, this.lab_level.string = (t.level || "1") + "级";
        break;

      case r.Basics_Items_Type.weapon:
        var i = r.GetCarWeaponData(t.id);
        this.lab_name.string = "" + i.name, this.lab_level.string = (t.level || "1") + "级";
        break;

      case r.Basics_Items_Type.tools:
        var n = r.GetCarToolsData(t.id);
        this.lab_name.string = "" + n.name, this.lab_level.string = (t.level || "1") + "级";
    }
  }, e.prototype.createItem = function (t) {
    if (!this.assemblyItem) {
      var e = cc.instantiate(this.pfb_assemblyItem);
      e.position = cc.v3(0, 0, 0), this.node_item.addChild(e), this.assemblyItem = e;
    }

    this.assemblyItem.getComponent(h.AssemblyItem).updateItem(null, !0, 0, t, !1, h.Assembly_Type.Sell);
  }, e.prototype.showStar = function (t) {
    this.nCurStar = t;
    var e;
    e = t % 2 == 1 ? [cc.v3(0, 0, 0), cc.v3(22, 0, 0), cc.v3(-22, 0, 0), cc.v3(43, 0, 0), cc.v3(-43, 0, 0)] : [cc.v3(11, 0, 0), cc.v3(-11, 0, 0), cc.v3(32, 0, 0), cc.v3(-32, 0, 0)];

    for (var o = 0; o < this.arrNode_star.length; o++) {
      o < t ? (this.arrNode_star[o].active = !0, this.arrNode_star[o].position = e[o]) : this.arrNode_star[o].active = !1;
    }
  }, e.prototype.playAudio = function (t) {
    l["default"].getInstance().SendMessage(d.Broadcast_Func.Audio, t);
  }, a([f(cc.Prefab)], e.prototype, "pfb_assemblyItem", void 0), a([f(cc.Node)], e.prototype, "node_item", void 0), a([f(cc.Label)], e.prototype, "lab_name", void 0), a([f(cc.Label)], e.prototype, "lab_level", void 0), a([f(cc.Node)], e.prototype, "node_hp", void 0), a([f(cc.Node)], e.prototype, "node_elec", void 0), a([f(cc.Node)], e.prototype, "node_damage", void 0), a([f(cc.Node)], e.prototype, "arrNode_star", void 0), a([f(cc.SpriteFrame)], e.prototype, "arr_starIcons", void 0), a([f(cc.Node)], e.prototype, "node_check", void 0), a([u], e);
}(cc.Component);

o["default"] = m;

cc._RF.pop();